home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / tde40.zip / bj_ctype.h < prev    next >
Text File  |  1994-06-05  |  4KB  |  86 lines

  1. /****************************  start of original comments  ***************/
  2. /* Editor:      TDE, the Thomson-Davis Editor
  3.  * Filename:    myctype.h
  4.  * Compiled by: Byrial Jensen
  5.  *
  6.  * This file is a replacement for the standard header file ctype.h
  7.  * and defines the same ctype macros as in ctype.h
  8.  * This file make use of the chartypes table in file prompts2.h
  9.  * The macro definitions are similar to those in ctype.h (at least for
  10.  * my complier: Turbo C 2.0) but there the _ctype table starts with EOF (-1),
  11.  * here first char is \0, so here is no need to adjust indexes in chartypes.
  12.  *
  13.  * Note: The standard library function atol( ) uses ctype.h to find and
  14.  * and pass thru leading space in its argument string before converting it to
  15.  * a number. So to avoid including of the original 257-byte _ctype table
  16.  * in the executable you can recompile atol( ) with the necessary changes
  17.  * to use this header file instead of ctype.h
  18.  */
  19. /************************** end of original comments  ******************/
  20.  
  21. /*
  22.  * Byrial, thank you for sending in your replacement ctype file.  I modified
  23.  * your code to work in Linux as well as in DOS.  Although I'm not sure, but
  24.  * I suspect that most, if not all, PC C compilers use a 257 byte look-up table.
  25.  * The reason for using a 257 byte table is because ANSI C requires the ctype
  26.  * functions to handle EOF as well as the 256 ASCII and extended ASCII
  27.  * characters, see:
  28.  *
  29.  *  Brian W. Kernighan and Dennis M. Ritchie, _The C Programming
  30.  *    Language_, 2nd edition, Prentice-Hall, Englewood Cliffs, New
  31.  *    Jersey, 1988, Appendix B2, pp 248-249, ISBN 0-13-110362-8.
  32.  *
  33.  *  P. J. Plauger, _The Standard C Library_, Prentice-Hall, Englewood
  34.  *    Cliffs, New Jersey, 1992, Chapter 2, "<ctype.h>", pp 25-46,
  35.  *    ISBN 0-13-131509-9.
  36.  *
  37.  *  Samuel P. Harbison and Guy L. Steele, Jr., _C, A Reference Manual_,
  38.  *    3rd edition, Prentice-Hall, Englewood Cliffs, New Jersey, 1991,
  39.  *    Chapter 12, "Character Processing", pp 277-283, ISBN 0-13-110933-2.
  40.  *
  41.  *
  42.  * Name:  TDE, the Thomson-Davis Editor
  43.  * Date:  November 13, 1993, version 3.2
  44.  *
  45.  * This code is released into the public domain, Frank Davis.
  46.  * You may distribute it freely.
  47.  *
  48.  *                             ctype in TDE
  49.  *
  50.  *  Instead of using the Standard C ctype library, we will use our own
  51.  *  ctype functions.  Our ctype functions are prefaced with bj_ (for
  52.  *  Byrial Jensen, who thought up our scheme.)  Our 257 byte tables are
  53.  *  at the bottom of the prompt.h file.  Our table defines ctypes for
  54.  *  characters in the range 128-255 (Standard C does not define this range),
  55.  *  which include accented characters used in various alphabets and languages.
  56.  *  So, we actually have two sets of ctype functions: Standard C and
  57.  *  Byrial Jensen.
  58.  */
  59.  
  60. #define BJ_cntrl    0x01  /* bit mask for control character */
  61. #define BJ_upper    0x02  /* bit mask for uppercase letter */
  62. #define BJ_lower    0x04  /* bit mask for lowercase letter */
  63. #define BJ_digit    0x08  /* bit mask for digit */
  64. #define BJ_xdigit   0x10  /* bit mask for hex digits */
  65. #define BJ_space    0x20  /* bit mask for space */
  66. #define BJ_punct    0x40  /* bit mask for printing characters except
  67.                                           space, letter, or digit */
  68.  
  69.  
  70. #define bj_isalnum(c)   (bj_ctype[(int)(c)+1] & (BJ_digit | BJ_upper | BJ_lower))
  71. #define bj_isalpha(c)   (bj_ctype[(int)(c)+1] & (BJ_upper | BJ_lower))
  72. #define bj_iscntrl(c)   (bj_ctype[(int)(c)+1] & BJ_cntrl)
  73. #define bj_isdigit(c)   (bj_ctype[(int)(c)+1] & BJ_digit)
  74. #define bj_islower(c)   (bj_ctype[(int)(c)+1] & BJ_lower)
  75. #define bj_ispunct(c)   (bj_ctype[(int)(c)+1] & BJ_punct)
  76. #define bj_isspace(c)   (bj_ctype[(int)(c)+1] & BJ_space)
  77. #define bj_isupper(c)   (bj_ctype[(int)(c)+1] & BJ_upper)
  78. #define bj_isxdigit(c)  (bj_ctype[(int)(c)+1] & BJ_xdigit)
  79.  
  80. /*
  81.  * These two functions are (re)defined in bj_ctype.c
  82.  */
  83. int  bj_tolower( int c );
  84. int  bj_toupper( int c );
  85.  
  86.